package com.gqb.lucene;

import java.io.File;
import java.io.IOException;
import java.util.TimerTask;

import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;

public class IndexTask extends TimerTask {
	private Indexer indexer;
	private Searcher searcher;
	
	
/*	public IndexTask(String indexDir,String dataDir) throws IOException {
		 indexer=new Indexer(indexDir, dataDir);
		 searcher=new Searcher(indexDir);
	}
*/

	@Override
	public void run() {
		System.out.println(System.currentTimeMillis());
		try {
			 indexer=new Indexer("d:\\lucene", "d:\\lucene\\data");
			 searcher=new Searcher("d:\\lucene");
			File[] files=new File("d:\\lucene\\data").listFiles();
			int i=0;
			for (File file : files) {
				i++;
				 TopDocs hits= searcher.TermQueryL("fileNameString", file.getName());
				 ScoreDoc[] scoreDocs=hits.scoreDocs;
				 if(scoreDocs.length<=0){
					 indexer.indexFile(file,i);
				 }
			}
			indexer.close();
			searcher.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
}
